﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;

namespace Kevin.Controls
{
    public class DataBindItemCoverter : ExpandableObjectConverter
    {
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return true;
            return base.CanConvertTo(context, destinationType);
        }
        public override object  ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string) && value is DataBindItem)
            {
                DataBindItem item = value as DataBindItem;

                return item.PropertyName;
            }
 	         return base.ConvertTo(context, culture, value, destinationType);
        }
    }
    public class DataBindItemCollectionCoverter : ExpandableObjectConverter
    {
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return true;
            return base.CanConvertTo(context, destinationType);
        }
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string) && value is DataBindItemCollection)
            {
                DataBindItemCollection items = value as DataBindItemCollection;

                return items.Count.ToString()+" Items";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}
